// 视立方插件鉴权
// 鉴权参考：https://cloud.tencent.com/document/product/616/71364

const LICENSE_KEY = '188fedf48825fbe0308f6cd805ebf149';
const APP_ID = '1305948708';
// token放在前端有泄漏风险，建议按照文档说明，将签名服务放到后端
const TOKEN = 'bd1fdcc43c76a22dada68e5219ce9519';

const {
	createHash
} = require('crypto');
const config = {
	appid: APP_ID,
	token: TOKEN,
}
const sha256 = function(str) {
	return createHash('sha256')
		.update(str)
		.digest('hex');
}


const genSignature = function() {
	const timestamp = Math.round(new Date().getTime() / 1000);
	const signature = sha256(timestamp + config.token + config.appid + timestamp)
.toUpperCase(); // 使用上面获取到的token和appid合成加密串返回
	return {
		signature,
		timestamp
	};
}
async function authFunc() {
	const {
		signature,
		timestamp
	} = genSignature();
	return {
		signature,
		timestamp,
	};
}

export {
	LICENSE_KEY,
	APP_ID,
	authFunc
};